﻿using System;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using RTMBindings.Model;

namespace MilkCart.Convertors
{
    public sealed class PriorityConverter : DependencyObject, IValueConverter
    {
        public Brush PriorityOneBrush
        {
            get { return (Brush)GetValue(PriorityOneBrushProperty); }
            set { SetValue(PriorityOneBrushProperty, value); }
        }

        public static readonly DependencyProperty PriorityOneBrushProperty =
            DependencyProperty.Register("PriorityOneBrush", typeof(Brush), typeof(PriorityConverter), new PropertyMetadata(default(Brush)));

        public static readonly DependencyProperty PriorityTwoBrushProperty =
            DependencyProperty.Register("PriorityTwoBrush", typeof (Brush), typeof (PriorityConverter), new PropertyMetadata(default(Brush)));

        public Brush PriorityTwoBrush
        {
            get { return (Brush) GetValue(PriorityTwoBrushProperty); }
            set { SetValue(PriorityTwoBrushProperty, value); }
        }

        public static readonly DependencyProperty PriorityThreeBrushProperty =
            DependencyProperty.Register("PriorityThreeBrush", typeof (Brush), typeof (PriorityConverter), new PropertyMetadata(default(Brush)));

        public Brush PriorityThreeBrush
        {
            get { return (Brush) GetValue(PriorityThreeBrushProperty); }
            set { SetValue(PriorityThreeBrushProperty, value); }
        }

        public static readonly DependencyProperty PriorityNoneBrushProperty =
            DependencyProperty.Register("PriorityNoneBrush", typeof (Brush), typeof (PriorityConverter), new PropertyMetadata(default(Brush)));

        public Brush PriorityNoneBrush
        {
            get { return (Brush) GetValue(PriorityNoneBrushProperty); }
            set { SetValue(PriorityNoneBrushProperty, value); }
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is RTMPriority))
                return null;
            var val = (RTMPriority)value;

            switch (val)
            {
                case RTMPriority.One:
                    return PriorityOneBrush;
                case RTMPriority.Two:
                    return PriorityTwoBrush;
                case RTMPriority.Three:
                    return PriorityThreeBrush;
                default:
                    return PriorityNoneBrush;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
